package com.example.planegame;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends Activity {

    private int speed = 10;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        final PlaneView planeView = new PlaneView(this);
        setContentView(planeView);
        //getActionBar().hide();

        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        int screenWidth = dm.widthPixels;
        int screenHeight = dm.heightPixels;

        planeView.offX(screenWidth / 2);
        planeView.offY(screenHeight * 4 / 5);

        planeView.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                switch (keyCode) {
                    case KeyEvent.KEYCODE_DPAD_LEFT:
                        planeView.offX(-speed);
                        break;
                    case KeyEvent.KEYCODE_DPAD_RIGHT:
                        planeView.offX(speed);
                        break;
                    case KeyEvent.KEYCODE_DPAD_UP:
                        planeView.offY(-speed);
                        break;
                    case KeyEvent.KEYCODE_DPAD_DOWN:
                        planeView.offY(speed);
                        break;
                }
                return false;
            }
        });
    }
}
